package cc.dewdrop.ffplayer;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.cplusplus.ffplayer.demo.R;
import com.example.cplusplus.ffplayer.demo.databinding.ActivityMainBinding;
import cc.dewdrop.ffplayer.utils.FFUtils;
import cc.dewdrop.ffplayer.widget.FFVideoView;

public class MainActivity extends AppCompatActivity {
    private TextView mTextView;
    private FFVideoView mVideoView;

    // Used to load the 'demo' library on application startup.
//    static {
//        System.loadLibrary("demo");
//    }

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        mTextView = findViewById(R.id.sample_text);
        mVideoView = findViewById(R.id.videoView);
    }

    /**
     * A native method that is implemented by the 'demo' native library,
     * which is packaged with this application.
     */

    public void onButtonClick(View view) {
        Log.e("MainActivity", "onButtonClick");
        Toast.makeText(this, "onButtonClick", Toast.LENGTH_LONG).show();
        int id = view.getId();

        if (id == R.id.button_protocol) {
            setInfoText(FFUtils.urlProtocolInfo());
        } else if (id == R.id.button_codec) {
            setInfoText(FFUtils.avCodecInfo());
        } else if (id == R.id.button_filter) {
            setInfoText(FFUtils.avFilterInfo());
        } else if (id == R.id.button_format) {
            setInfoText(FFUtils.avFormatInfo());
        } else if (id == R.id.button_play) {
            String videoPath = Environment.getExternalStorageDirectory() + "/Movies/1.mp4";
            Log.e("MainActivity", "videoPath:" + videoPath);
            Toast.makeText(this, "videoPath:" + videoPath, Toast.LENGTH_LONG).show();
            mVideoView.playVideo(videoPath);
        }
    }

    private void setInfoText(String content) {
        if (mTextView != null) {
            mTextView.setText(content);
        }
    }
}

